from selenium import webdriver
from selenium.webdriver.common.by import By
drive=webdriver.Firefox()
from selenium.webdriver.common.keys import Keys
from  selenium.webdriver.support.ui import  WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

"""
1、163邮箱的账号密码区域的input标签的id是自动生成的，每次都不能用，所以不能用于定位标签 
2、登陆处是一个iframe，需要程序中切换一下：drive.switch_to.frame()，不然会找不到标签 
3、加载这个iframe需要一定时间，所以需要设一个等待直至获取到标签: 
element=WebDriverWait(drive,30,0.5).until(EC.presence_of_element_located((By.XPATH,”//*[@id=’x-URS-iframe’]”)))
"""

drive.get("http://mail.163.com/")
element=WebDriverWait(drive,30,0.5).until(EC.presence_of_element_located((By.XPATH,"//*[@id='x-URS-iframe']"))) #等待直到出现填写账号密码iframe
# 切换标签
drive.switch_to.frame("x-URS-iframe")
# 定位到账号框
inputText=drive.find_element(By.XPATH,"//*[@id='account-box']//div[2]//input")
inputText.send_keys("m18361480741")
password=drive.find_element(By.XPATH,"//*[@id='login-form']//div//div[3]//div[2]//input[2]")
password.send_keys("zenglong19940519")
# 模拟回车键
password.send_keys(Keys.ENTER)

time.sleep(5)
drive.quit()
